<div ng-controller="Purchasing_DirectorC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">采购单列表</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <a class="btn btn-sm btn-default" href={{myurl}}>
                        <i class="fa fa-cloud-download text"></i>
                        <span class="text">导出</span>
                    </a>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 input-group">
                    <div class="input-group">
                        <span class="input-group-addon">按申请人查找</span>
                        <input type="text" class="form-control" id='findname' placeholder="按申请人查找" ng-model="findname">
                        <span class="input-group-addon">按日期查找</span>
                        <input type="date" class="form-control" placeholder="按日期查找" ng-model="qTime">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                        </span>
                    </div>
                </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light table-bordered">
                    <thead>
                        <tr>
                            <th style="text-align: center;">日期</th>
                            <th style="text-align: center;">供应商</th>
                            <th style="text-align: center;">数量（t）</th>
                            <th style="text-align: center;">金额（元）</th>
                            <th style="text-align: center;">库房</th>
                            <th style="text-align: center;">户头</th>
                            <th style="text-align: center;">申请人</th>
                            <th style="text-align: center;">备注</th>
                            <th style="text-align: center;">状态</th>
                            <th style="text-align: center;">操作</th>

                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="item in orders">
                            <td style="width:13%">{{item.CreateTime}}</td>
                            <td style="width:10%">{{item.Provider.Name}}</td>
                            <td style="width:10%">{{item.TotalWeight | number:3}}t</td>
                            <td style="width:10%">{{item.Total | number:2}}</td>
                            <td style="width:10%">{{item.ToDepot.Name}}</td>
                            <td style="width:10%">{{item.Account}}</td>
                            <td style="width:10%">{{item.Creater.Name}}</td>
                            <td style="width:10%">{{item.Remarks}}</td>
                            <td style="width:10%" ng-if="item.State == 0">待确认</td>
                            <td style="width:10%" ng-if="item.State == 1">审批中</td>
                            <td style="width:10%" ng-if="item.State == 2">采购中</td>
                            <td style="width:10%" ng-if="item.State == 3">取消</td>
                            <td style="width:10%" ng-if="item.State == 4">完成采购</td>
                            <td style="width:10%" ng-if="item.State == 5">入库审批</td>
                            <td style="width:10%" ng-if="item.State == 6">已入库</td>
                            <td style="width:10%" ng-if="item.State == 7">已发货</td>
                            <td style="width:7%">
                                <button class="btn btn-sm btn-default" ng-click="detail($index)">
                                    <i class="fa fa-file-text-o text"></i>
                                    <span class="text">详情</span>
                                </button>
                            </td>

                        </tr>
                    </tbody>
                </table>
                <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
            </div>
        </div>
    </div>
</div>
<script>
    angular.module('app')
            //计划单列表控制器
            .controller("Purchasing_DirectorC", function ($scope, $state, $http, toSave) {
                $scope.pageData = {};
                $scope.pageData.Page = 0;
                $scope.findname = "";
                $scope.qTime = new Date();
                $scope.pageData.Rows = $scope.defPageRows;
                $scope.myurl = "../api/Director/ExpPurchaseList?createTime=" + $scope.qTime + "&state=&name=" + $scope.findname;
                $scope.getData = function (p, r) {
                    if (p) {
                        p = p < 1 ? 1 : p;
                    } else p = 1;
                    if (r) {
                    } else r = $scope.defPageRows;
                    console.log($scope.qTime);
                    toSave.save_pages_lis(p, r);//保存当前页码和条数
                    $http.get("../api/Director/PurchaseList", { params: { page: p, rows: r, createTime: $scope.qTime, name: $scope.findname, state: "" } })
                            .then(function (res) {
                                $scope.orders = res.data.Data;
                                $scope.pageData = res.data;
                            })
                            .then(function (error) {
                                if (error) {
                                    alert("数据获取失败");
                                }
                            });
                };
                $scope.detail = function (index) {
                    $state.go("app.Director_PurchasingDetail", {
                        orderid: JSON.stringify($scope.orders[index].Id),
                        type:0
                    });
                };
                $scope.find = function () {
                    $scope.getData(1, $scope.pageData.Rows);
                    toSave.save_inputs();//点击查询先保存input里面的值
                    console.log(toSave.get_inputs('findname'))
                };
                //加载数据
                if (toSave.get_inputs('findname')) {
                    $scope.findname = toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
                    $scope.getData(toSave.get_pages(), toSave.get_lis());
                } else {
                    $scope.getData(1, $scope.pageData.Rows);
                }
            })
</script>
<script src="js/services/toSave.js"></script>